const express = require('express');
const router = express.Router();
const { body } = require('express-validator');
const draftController = require('../controllers/draftController');
const authMiddleware = require('../middleware/auth').authMiddleware;

// 保存草稿（创建或更新）
router.post('/', [
  authMiddleware,
  body('content').notEmpty().withMessage('草稿内容不能为空')
], draftController.saveDraft);

// 获取用户的草稿列表
router.get('/', authMiddleware, draftController.getUserDrafts);

// 获取单个草稿详情
router.get('/:id', authMiddleware, draftController.getDraftById);

// 删除草稿
router.delete('/:id', authMiddleware, draftController.deleteDraft);

// 将草稿发布为笔记
router.post('/:id/publish', authMiddleware, draftController.publishDraft);

module.exports = router;